def I2S(x):
    a=x//16777216
    b=(x%16777216)//65536
    c=(x%65536)//256
    d=x%256
    return chr(a) + chr(b) + chr(c) + chr(d) 

with open("abilitydata.txt",'r',encoding = "utf-8") as fi:
    r_str = fi.read()

r_list = r_str.splitlines(False)

ability = {}
for line in r_list:
    if "[" in line :
        _id = str(line[1:-1])
    if 'Name' in line :
        ability[_id] = line[5:]

with open("abilityid.txt",'r',encoding = "utf-8") as fi:
    r_str = fi.read()

r_list = r_str.splitlines(False)

Data = []
for i in range(1000):
    Data.append("")

for line in r_list:
    ES = line.partition(",")[2]
    ES1 = ES.partition(",")[2]
    ES2 = ES1.partition(",")[2]
    _number = int(ES.partition(",")[0])
    _id = I2S(int(ES2[1:-1],16))
    Data[_number] = ability[_id]

r_str = ""
for line in Data:
    if line != "" :
        r_str += str(Data.index(line)) + "\t" + line + "\n"

with open('data.txt','w') as fi:
    fi.write(r_str)

pass